home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- import re
- import string
- import posixpath
- from checkbox.lib.cache import cache
- from checkbox.lib.dmi import DmiNotAvailable
- from checkbox.lib.pci import Pci
- from checkbox.lib.usb import Usb
- from checkbox.properties import String
- from checkbox.registry import Registry
- from checkbox.registries.command import CommandRegistry
- from checkbox.registries.link import LinkRegistry
- from checkbox.registries.map import MapRegistry
-
- class UnknownName(object):
-
- def __init__(self, function):
- self._function = function
-
-
- def __get__(self, instance, cls = None):
- self._instance = instance
- return self
-
-
- def __call__(self, *args, **kwargs):
- name = self._function(self._instance, *args, **kwargs)
- if name and name.startswith('Unknown ('):
- name = None
-
- return name
-
-
-
- class DeviceRegistry(Registry):
- '''Registry for HAL device information.
-
- Each item contained in this registry consists of the properties of
- the corresponding HAL device.
- '''
-
- def __init__(self, properties):
- self._properties = properties
-
-
- def __str__(self):
- strings = _[1]
- return '\n'.join(strings)
-
-
- def _get_bus(self):
- return self._properties.get('linux.subsystem')
-
-
- def _get_category(self):
- if 'system.hardware.vendor' in self._properties:
- return 'SYSTEM'
- if 'net.interface' in self._properties:
- return 'NETWORK'
- if 'pci.device_class' in self._properties:
- class_id = self._properties['pci.device_class']
- subclass_id = self._properties['pci.device_subclass']
- if class_id == Pci.BASE_CLASS_NETWORK:
- return 'NETWORK'
- if class_id == Pci.BASE_CLASS_DISPLAY:
- return 'VIDEO'
- if class_id == Pci.BASE_CLASS_SERIAL and subclass_id == Pci.CLASS_SERIAL_USB:
- return 'USB'
- if class_id == Pci.BASE_CLASS_COMMUNICATION and subclass_id == Pci.CLASS_COMMUNICATION_MODEM:
- return 'MODEM'
- if class_id == Pci.BASE_CLASS_INPUT and subclass_id == Pci.CLASS_INPUT_SCANNER:
- return 'SCANNER'
- if class_id == Pci.BASE_CLASS_SERIAL and subclass_id == Pci.CLASS_SERIAL_FIREWIRE:
- return 'FIREWIRE'
- if self._get_product_id():
- return 'OTHER'
-
-
- def _get_driver(self):
- return self._properties.get('info.linux.driver')
-
-
- def _get_path(self):
- return self._properties.get('linux.sysfs_path', '').replace('/sys', '')
-
-
- def _get_product_id(self):
- if 'info.subsystem' in self._properties:
- product_id = '%s.product_id' % self._properties['info.subsystem']
- if product_id in self._properties:
- return self._properties[product_id]
-
- if 'pnp.id' in self._properties:
- match = re.match('^(?P<vendor_name>.*)(?P<product_id>[%s]{4})$' % string.hexdigits, self._properties['pnp.id'])
- if match:
- return int(match.group('product_id'), 16)
-
-
-
- def _get_vendor_id(self):
- if 'info.subsystem' in self._properties:
- vendor_id = '%s.vendor_id' % self._properties['info.subsystem']
- if vendor_id in self._properties:
- return self._properties[vendor_id]
-
-
-
- def _get_subproduct_id(self):
- return self._properties.get('pci.subsys_product_id')
-
-
- def _get_subvendor_id(self):
- return self._properties.get('pci.subsys_vendor_id')
-
-
- def _get_product(self):
- bus = self._get_bus()
- if bus in ('drm', 'net', 'platform', 'pci', 'pnp', 'scsi_generic', 'scsi_host', 'tty', 'usb', 'video4linux'):
- return None
- if 'usb.interface.number' in self._properties:
- return None
- if self._properties.get('info.category') == 'ac_adapter':
- return None
- for property in ('alsa.device_id', 'alsa.card_id', 'sound.card_id', 'battery.model', 'ieee1394.product', 'killswitch.name', 'oss.device_id', 'scsi.model', 'system.hardware.product', 'info.product'):
- if property in self._properties:
- return self._properties[property]
-
-
- _get_product = UnknownName(_get_product)
-
- def _get_vendor(self):
- bus = self._get_bus()
- if bus in ('drm', 'pci', 'rfkill', 'usb'):
- return None
- for property in ('battery.vendor', 'ieee1394.vendor', 'scsi.vendor', 'system.hardware.vendor', 'info.vendor'):
- if property in self._properties:
- return self._properties[property]
-
-
- _get_vendor = UnknownName(_get_vendor)
-
- def items(self):
- return (('path', self._get_path()), ('bus', self._get_bus()), ('category', self._get_category()), ('driver', self._get_driver()), ('product_id', self._get_product_id()), ('vendor_id', self._get_vendor_id()), ('subproduct_id', self._get_subproduct_id()), ('subvendor_id', self._get_subvendor_id()), ('product', self._get_product()), ('vendor', self._get_vendor()), ('properties', MapRegistry(self._properties)), ('device', LinkRegistry(self)))
-
-
-
- class DmiDeviceRegistry(DeviceRegistry):
- _category_to_property = {
- 'BIOS': 'system.firmware',
- 'BOARD': 'system.board',
- 'CHASSIS': 'system.chassis' }
-
- def __init__(self, properties, category):
- super(DmiDeviceRegistry, self).__init__(properties)
- if category not in self._category_to_property:
- raise Exception, 'Unsupported category: %s' % category
- category not in self._category_to_property
- self._category = category
-
-
- def _property(self):
- return self._category_to_property[self._category]
-
- _property = property(_property)
-
- def _get_category(self):
- return self._category
-
-
- def _get_path(self):
- path = super(DmiDeviceRegistry, self)._get_path()
- return posixpath.join(path, self._category.lower())
-
-
- def _get_product(self):
- for subproperty in ('product', 'type', 'version'):
- property = '%s.%s' % (self._property, subproperty)
- product = self._properties.get(property)
- if product and product != 'Not Available':
- return product
-
-
-
- def _get_vendor(self):
- for subproperty in ('vendor', 'manufacturer'):
- property = '%s.%s' % (self._property, subproperty)
- if property in self._properties:
- return self._properties[property]
-
-
- _get_vendor = DmiNotAvailable(_get_vendor)
-
-
- class HalRegistry(CommandRegistry):
- '''Registry for HAL information.
-
- Each item contained in this registry consists of the udi as key and
- the corresponding device registry as value.
- '''
- command = String(default = 'lshal')
- _deprecated_expressions = (('info\\.bus', 'info.subsystem'), ('([^\\.]+)\\.physical_device', '\x01.originating_device'), ('power_management\\.can_suspend_to_ram', 'power_management.can_suspend'), ('power_management\\.can_suspend_to_disk', 'power_management.can_hibernate'), ('smbios\\.system\\.manufacturer', 'system.hardware.vendor'), ('smbios\\.system\\.product', 'system.hardware.product'), ('smbios\\.system\\.version', 'system.hardware.version'), ('smbios\\.system\\.serial', 'system.hardware.serial'), ('smbios\\.system\\.uuid', 'system.hardware.uuid'), ('smbios\\.bios\\.vendor', 'system.firmware.vendor'), ('smbios\\.bios\\.version', 'system.firmware.version'), ('smbios\\.bios\\.release_date', 'system.firmware.release_date'), ('smbios\\.chassis\\.manufacturer', 'system.chassis.manufacturer'), ('smbios\\.chassis\\.type', 'system.chassis.type'), ('system\\.vendor', 'system.hardware.vendor'), ('usb_device\\.speed_bcd', 'usb_device.speed'), ('usb_device\\.version_bcd', 'usb_device.version'))
-
- def __init__(self, *args, **kwargs):
- super(HalRegistry, self).__init__(*args, **kwargs)
- self._deprecated_patterns = (lambda .0: for a, b in .0:
- (re.compile('^%s$' % a), b))(self._deprecated_expressions)
-
-
- def _get_key(self, key):
- for old, new in self._deprecated_patterns:
- key = old.sub(new, key)
-
- return key
-
-
- def _get_value(self, value, type):
- value = value.strip()
- if type == 'bool':
- value = bool(value == 'true')
- elif type == 'double':
- value = float(value.split()[0])
- elif type == 'int' or type == 'uint64':
- value = int(value.split()[0])
- elif type == 'string':
- value = str(value.strip("'"))
- elif type == 'string list':
- value = [ v.strip("'") for v in value.strip('{}').split(', ') ]
- else:
- raise Exception, 'Unknown type: %s' % type
- return []
-
-
- def _ignore_device(self, device):
- if not device.bus:
- return True
- if not (device.product) and device.product_id is None:
- return True
- if (device.subproduct_id is None or device.subvendor_id is not None or device.subproduct_id is not None) and device.subvendor_id is None:
- return True
- if device.bus != 'dmi' and 'virtual' in device.path.split(posixpath.sep):
- return True
- return False
-
-
- def items(self):
- devices = []
- for record in self.split('\n\n'):
- if not record:
- continue
-
- name = None
- properties = { }
- for line in record.split('\n'):
- match = re.match("udi = '(.*)'", line)
- if match:
- udi = match.group(1)
- name = udi.split(posixpath.sep)[-1]
- continue
-
- match = re.match(' (?P<key>.*) = (?P<value>.*) \\((?P<type>.*?)\\)', line)
- if match:
- key = self._get_key(match.group('key'))
- value = self._get_value(match.group('value'), match.group('type'))
- properties[key] = value
- continue
-
- if name == 'computer':
- properties['linux.subsystem'] = 'dmi'
- properties['linux.sysfs_path'] = '/sys/devices/virtual/dmi/id'
- device = DeviceRegistry(properties)
- devices.append(device)
- for category in ('BIOS', 'BOARD', 'CHASSIS'):
- device = DmiDeviceRegistry(properties, category)
- devices.append(device)
-
- device = DeviceRegistry(properties)
- devices.append(device)
-
- return _[1]
-
- items = cache(items)
-
- factory = HalRegistry
-